package com.example.managesystem.mapper;

import com.example.managesystem.dto.AnnoDTO;
import com.example.managesystem.dto.AnnoPageQueryDTO;
import com.example.managesystem.entity.Anno;
import com.example.managesystem.vo.AnnoMaintextVO;
import com.example.managesystem.vo.AnnoVO;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AnnoMapper {

    /**
     * 查询所有公告
     * @return
     */
    @Select("select id,title,create_time from announcment")
    public List<AnnoVO> queryAllAnno();

    /**
     * 查询单个公告
     * @param id
     * @return
     */
    @Select("select title,maintext from announcment where id=#{id}")
    AnnoMaintextVO getAnnoById(Integer id);

    /**
     * 分页查询公告
     * @param annoPageQueryDTO
     * @return
     */
    Page<AnnoVO> pagequeryByDTO(AnnoPageQueryDTO annoPageQueryDTO);

    void deleteAnnos(@Param("annoids") List<Long> annoids);

    /**
     * 添加公告
     * @param anno
     */
    @Insert("insert into announcment(title,dept,maintext,create_time) values(#{anno.title},#{anno.dept},#{anno.maintext},#{anno.create_time})")
    void insertAnno(@Param("anno") Anno anno);

    @Update("update announcment set title=#{annoDTO.title},maintext=#{annoDTO.maintext} where id=#{annoDTO.id}")
    void updateAnno(@Param("annoDTO")AnnoDTO annoDTO);
}
